<%@page import="com.powroznik.tracker.engine.services.Device"%>
<%@page import="com.powroznik.tracker.engine.services.Account"%>
<%@page import="com.powroznik.tracker.engine.services.User"%>
<%@page import="com.powroznik.tracker.liferay.portlet.Client"%>
<%@page import="java.util.List"%>
<%@page import="org.apache.commons.lang3.StringUtils"%>

<%@ taglib prefix="aui" uri="http://liferay.com/tld/aui"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0"%>

<portlet:defineObjects />

<portlet:renderURL var="viewURL">
	<portlet:param name="jspPage"
		value="/html/connecteddevicesportlet/view.jsp" />
</portlet:renderURL>

<%
	Client client = Client.getInstance(request);
	client.setUserKey(renderRequest.getRemoteUser());
	Account account = client.getAccount();
%>

<%
	if (account == null) {
%>

<p>Your user does not appear to be linked to any account. In order
	to use all features of this application, you first need to register
	your account.</p>

<%
	} else {
		List<Device> devices = client.getConnectedDevices();
		request.setAttribute("devices", devices);
%>

<style type="text/css">
table.connectedDevices {
	border: solid 1px #a0a0a0;
}

table.connectedDevices tr {
	border: solid 1px #a0a0a0;
}

table.connectedDevices th {
	background-color: #c0c0c0;
	border: solid 1px #a0a0a0;
	padding: 5px;
	text-align: center;
}

table.connectedDevices td {
	background-color: #ffffff;
	border: solid 1px #a0a0a0;
	padding: 5px;
}
</style>

<p>Devices that are connected to your account:</p>

<table class="connectedDevices">
	<tr>
		<th>Code</th>
		<th>Description</th>
	</tr>
	<c:forEach var="device" items="${devices}">
		<tr>
			<td>${device.code1}</td>
			<td>${device.description}</td>
		</tr>
	</c:forEach>
</table>

<%
	}
%>